import { dateFormat } from "../utils/common";
import request from "../utils/request";

export async function get237() {
  let id = "011b111e43bc41618fa8ef8097d6ee92";
  const id237Key = "237ID";
  const id237 = localStorage.getItem(id237Key);
  if (id237 !== null) {
    id = id237;
  }

  const url = `/zhaoji/country/nextCountry?id=${id}&time=${dateFormat(new Date(), "yyyy-MM-dd")}`;
  try {
    const res = await fetch(url, { method: "post" });
    const text = await res.text();
    let text_res = JSON.parse(text);
    text_res = text_res.data;
    const reg = /\[|"|]/g;
    const a = text_res.describes.split(",");
    text_res.describes = a.map((s) => s.replace(reg, ""));
    localStorage.setItem(id237Key, text_res.id);
    return Promise.resolve(text_res);
  } catch (e) {
    return Promise.reject(e);
  }
}
